package org.batatasframework.bytecode;

import org.batatasframework.bytecode.spi.AsmLoadable;
import org.springframework.asm.MethodVisitor;

/**
 * <pre>
 * 封装用于对一个方法的调用可用于另一个调用的取值表达式
 * 
 * 注意：这种方法的调用必须有返回值，否则无法赋值给别一个变量
 * 
 * 临时没有限制必须有返回值的，使用的时候注意
 * </pre>
 * @author jackson
 *
 */
public class AsmMethodLoader implements AsmLoadable{
	
	private final AsmLoadable object;
	private final MethodAsminfo method;
	private final AsmLoadable[] params;
	
	public AsmMethodLoader(AsmLoadable object, MethodAsminfo method, AsmLoadable... params){
		this.object = object;
		this.method = method;
		this.params = params;
	}
	
	@Override
	public void load(MethodVisitor visitor, ClassAsminfo targetType) {
		method.invoke(object, visitor, params);
		targetType.cast(visitor, method.getResultClass());
	}

	@Override
	public void load(MethodVisitor visitor) {
		method.invoke(object, visitor, params);
	}

}
